import variables from '@/assets/styles/element-variables.scss'
import defaultSettings from '@/settings'
import Cookies from 'js-cookie'

const { sideTheme, showSettings, tagsView, fixedHeader, sidebarLogo } = defaultSettings
const state = {
  theme: Cookies.get('theme') ? Cookies.get('theme') : variables.theme,
  sideTheme: Cookies.get('sideTheme') ? Cookies.get('sideTheme') : sideTheme,
  showSettings: showSettings,
  tagsView: true,//Cookies.get('tagsView',true),
  fixedHeader: false,//Cookies.get('fixedHeader',false),
  sidebarLogo: true//Cookies.get('sidebarLogo',false),
}

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    if (state.hasOwnProperty(key)) {
      state[key] = value
      Cookies.set(key,value)
    }
  }
}

const actions = {
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

